package com.example.controller.institutioncare.fuwuxinxi;

import com.example.bean.configuration.zhibiaosystem.XzLiebiao;
import com.example.bean.institutioncare.fuwuxinxi.FuWuXinXi;
import com.example.bean.institutioncare.fuwuxinxi.FuWuXinXiVo;
import com.example.service.institutioncare.fuwuxinxi.FuWuXinXiService;
import com.example.utils.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/fuwuxinxi")
public class FuWuXinXiController {

    @Autowired
    FuWuXinXiService fuWuXinXiService;

    @PostMapping("/page")
    public PageInfo<FuWuXinXi> fuwupage(@RequestBody FuWuXinXiVo fuWuXinXiVo){
        System.err.println(fuWuXinXiVo);
        return fuWuXinXiService.pagefuwuxinxi(fuWuXinXiVo);
    }

    @PostMapping("/addfuwu")
    public Result tianjiafuwu(@RequestBody FuWuXinXi fuWuXinXi){
        Integer fuwu = fuWuXinXiService.addFuWuXinXi(fuWuXinXi);
        Result re = new Result();
        re.setCode(fuwu);
        return re;
    }

    @PostMapping("/chazhibiao")
    public Result chazhibiao(){
        List<XzLiebiao> list = fuWuXinXiService.listzhibiao();
        Result re = new Result();
        re.setData(list);
        return re;
    }

    @GetMapping("/{noid}")
    public Result huixianfuwu(@PathVariable String noid){
        FuWuXinXi fuwu = fuWuXinXiService.huixianfuwuxinxi(noid);
        Result re = new Result();
        if (fuwu != null){
            re.ok();
            re.setData(fuwu);
        }else {
            re.fail("回显失败");
        }
        return re;
    }

    @PostMapping("/xiugai")
    public Result xiugaifuwu(@RequestBody FuWuXinXi fuWuXinXi){
        Integer xiugai = fuWuXinXiService.xiugaifuwu(fuWuXinXi);
        Result re = new Result();
        if (xiugai > 0){
            re.ok();
        }else {
            re.fail("修改失败");
        }
        return re;
    }

    @PostMapping("/shanchu")
    public Result shanchufuwu(@RequestBody List<String> ids){
        Integer shanfuwu = fuWuXinXiService.shanchufuwu(ids);
        Result re = new Result();
        if (shanfuwu > 0){
            re.ok();
        }else {
            re.fail("删除失败");
        }
        return re;
    }

}
